package com.randy.fundation;

public class JxTypeUtils {
    public static <T> T from(Object o) {
        try {
            return (T) o;
        } catch (ClassCastException e) {
            return null;
        }
    }

    public interface AsCallback<T> {
        void yield(T obj);
    }

    public static <T> void as(Object o, Class<T> clazz, AsCallback<T> callback) {
        try {
            T v = clazz.cast(o);
            with(v, callback);
        } catch (ClassCastException e) {
            // Logger.w(e.getMessage());
        }
    }

    public static <T> void with(T o, AsCallback<T> callback) {
        if (o != null && callback != null) {
            callback.yield(o);
        }
    }
}
